<?php
namespace app\portal\controller;
use app\portal\model\TeacherModel;
use cmf\controller\AdminBaseController;
use app\portal\model\PortalPostModel;

use think\Db;
use app\admin\model\ThemeModel;
class AdminTeacherController extends AdminBaseController{
    public function index()
    {
        $model = new TeacherModel();
        $data = $model->getAll();
        //dump($data);
        $this->assign('data',$data);
        return $this->fetch();
    }
    /**
     * 文章删除
     * @adminMenu(
     *     'name'   => '文章删除',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '文章删除',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $teacherModel = new TeacherModel();
        $id = $this->request->param('id');
        $code = $teacherModel->where(['id' => ['eq', $id]])->delete();
        //dump($code);
        if($code){
            $this->success("删除成功！");
        }
        else
        {
            $this->error("删除失败");
        }
    }
    public function recommend()
    {
        $param= $this->request->param();
        //dump($param);

            $teacherModel = new TeacherModel();
            if (isset($param["tj"])) {
                $ids = $this->request->param('ids/a');
                $code = $teacherModel->where(['id' => ['in', $ids]])->update(['status' => 1]);
                //dump($code);
                if($code){
                    $this->success("推荐成功！");
                }
                else
                {
                    $this->error("推荐失败");
                }

            }
            else if (isset($param["qx"])) {
                $ids = $this->request->param('ids/a');
                $code = $teacherModel->where(['id' => ['in', $ids]])->update(['status' => 0]);
                //dump($code);
                if($code){
                    $this->success("取消推荐成功！");
                }
                else
                {
                    $this->error("取消推荐失败");
                }

            }
            else if(isset($param["delete"])) {
                $ids = $this->request->param('ids/a');
                $code = $teacherModel->where(['id' => ['in', $ids]])->delete();
                //dump($code);
                if($code){
                    $this->success("删除成功！");
                }
                else
                {
                    $this->error("删除失败");
                }


            }




    }
}
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/15 0015
 * Time: 下午 2:03
 */